package com.njwb.day15.zqzb.ios.io7;

import com.njwb.day15.zqzb.ios.pojo.Student;
import com.njwb.day15.zqzb.ios.util.Util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

public class ObjectOutputStreamDemo {
    public static void main(String[] args) {
        ObjectOutputStream oos =  null ;


        try {
            oos = new ObjectOutputStream(new FileOutputStream(new File("src/oos.txt")));
            Student[]  students = new Student[3];
            students[0] = new Student("张三",12,"南京");
            students[1] = new Student("李四",12,"南京");
            students[2] = new Student("赵9",12,"南京");
            //写对象
            oos.writeObject(students);

            oos.flush();

        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            Util.closeResource(oos);
        }
    }
}
